<?php

/**
 * SocialEngine
 *
 * @category   Application_Core
 * @package    Core
 * @copyright  Copyright 2006-2010 Webligo Developments
 * @license    http://www.socialengine.net/license/
 * @version    $Id: ListItems.php 7244 2010-09-01 01:49:53Z john $
 * @author     John
 */

/**
 * @category   Application_Core
 * @package    Core
 * @copyright  Copyright 2006-2010 Webligo Developments
 * @license    http://www.socialengine.net/license/
 */
class Seaocore_Model_DbTable_Locations extends Engine_Db_Table {

  protected $_rowClass = 'Seaocore_Model_Location';
  protected $_location;

 // Set the location
  public function setLocation($location=array()) {
    $select = $this->select()
            ->where('location = ?', $location['location']);
    $row = $this->fetchRow($select);
    if ($row == null) {
      $row = $this->createRow();
      $row->setFromArray($location);
    }
    if (null !== $row) {
      $row->setFromArray($location);
    }
    $row->save();

    return $row->location_id;
  }
 // Get the location
  public function getLocation($location=array()) {
    $select = $this->select();
    foreach ($location as $key => $value) {
      $select->where(" $key = ?", $value);
    }
    return $this->fetchRow($select);
  }
 // Check the location
  public function hasLocation($location=array()) {
    $flage = 0;

    $result = $this->getLocation($location);
    if (!empty($result)) {
      $flage = 1;
    }

    return $flage;
  }
 // Delete the location
  public function clearLocation() {
    $result = $this->getLocation($location);
     if (!empty($result)) {
      $result->delete();
    }

  }

//   public function setTagLocation($tag_id, $tag_location, $location, $latitude, $longitude) {
//   
//     $select = $this->select()->from($this->info('name'), array('location', 'location_id'))->where('location =?', $location);
//     $locationTableRow = $this->fetchRow($select);
// 
//     if (empty($locationTableRow) && (empty($tag_id) && empty($tag_location)) && !empty($location)) {
//       $locationRow = $this->createRow();
//       $locationRow->location = $location;
//       $locationRow->latitude = $latitude;
//       $locationRow->longitude = $longitude;
//       if (Engine_Api::_()->getApi('settings', 'core')->getSetting('sitetagcheckin.tagged.location', 1))
//         $locationRow->previous_tagged_location = 1;
//       $location_id = $locationRow->save();
//     } else {
//       if (!empty($locationTableRow->location_id))
//         $location_id = $locationTableRow->location_id;
//     }
// 
//     if (!empty($tag_id) || !empty($tag_location)) {
//       $tag_type = "sitepage_location";
//       $location_id = $tag_id;
//       $location = $tag_location;
//       if (Engine_Api::_()->getApi('settings', 'core')->getSetting('sitetagcheckin.tagged.location', 1))
//         $this->update(array('previous_tagged_location' => 1), array('location =?' => $location));
//     }
//  
//   }

}